var menuContainer;
function MenuContainer(){
   this.container = new Array();
   this.onmouseover = menu_mouseover;
   this.onmouseout = menu_mouseout;
   this.click = menu_click;
   this.id = null;
   this.parameters = null;
   this.listener = [];
}
MenuContainer.init = function(list){
    menuContainer = new MenuContainer();
    menuContainer.addMenuList(list);
    menuContainer.createMenu();
}
MenuContainer.display = function(arr){
    for(var i=0;i<arr.length;i++){
       var item = "menuitem_"+arr[i]; 
       item =  document.all(item);
       if(item){
         item.style.display = "";
       }
    }
}

MenuContainer.hidden = function(arr){
    for(var i=0;i<arr.length;i++){
       var item = "menuitem_"+arr[i]; 
       item =  document.all(item);
       if(item){
         item.style.display = "none";
       }
    }
}

MenuContainer.useable = function(arr){
    for(var i=0;i<arr.length;i++){
       var item = "menuitem_"+arr[i]; 
       item =  document.all(item);
       if(item){
          item.className = "T_song_mouseout";
          item.onmouseover= "menuContainer.onmouseover(this)";
          item.onmouseout= "menuContainer.onmouseout(this)";
          item.cell(0).onclick = "menuContainer.click('"+ arr[i] +"')";
          item.cell(0).className = "T_song12_wtt";
       }
    }
}

MenuContainer.disabled = function(arr){
     for(var i=0;i<arr.length;i++){
       var item = "menuitem_"+arr[i]; 
       item =  document.all(item);
       if(item){
          item.className = "T_song_disabled";
          item.onmouseover= "";
          item.onmouseout= "";
          item.cell(0).onclick = "";
          item.cell(0).className = "T_song_disabled";
       }
    }
}

MenuContainer.prototype.addMenu = function(menu){
   this.container[this.container.length] = menu;
}
MenuContainer.prototype.addMenuList = function(list){
   this.container = list;
}
MenuContainer.prototype.showMenu = function(id,parameters){
    
    this.id = id;
    this.parameters = parameters;    
    if(document.all.showrightmenu.style.display == "") return;
    var showTop,showLeft;    
    showTop = window.event.y;
    if((document.body.clientHeight - showTop)<52&&showTop>=52)
       showTop = showTop - 52;
    showTop = showTop + document.body.scrollTop ;               
    showLeft = window.event.x ;
    if(document.body.clientWidth<(showLeft+50)&&showLeft>=50)
       showLeft = showLeft -50;
    showLeft=showLeft + document.body.scrollLeft;

    document.all.showrightmenu.style.left = showLeft;
    document.all.showrightmenu.style.top = showTop; 
    document.all.showrightmenu.style.display = ""; 
}
MenuContainer.prototype.createMenu = function(){
   if(!this.container||this.container.length==0) return;
   
   var reHtml = "<div id='showrightmenu' class='rightMenuDiv' onmouseleave='menuContainer.hidden()' >";
   reHtml+="<table STYLE=\"border-collapse: separate;background-color: #e6e6e6\" bordercolordark='#FFFFFF' bordercolorlight='#848284' cellpadding='2' border='1' width='100%' height='100%' cellspacing=\"0\" cellpadding=\"3\" >";
   for(var i=0;i<this.container.length;i++){
      reHtml+="<tr widht='100%' id='menuitem_"+ this.container[i].id+ "' "+(!this.container[i].display?"style='display:none'":"")+" onmouseover='menuContainer.onmouseover(this)' onmouseout='menuContainer.onmouseout(this)' style='width:20px' class='T_song_mouseout'>";
      reHtml+="<td onclick=menuContainer.click('"+ this.container[i].id +"'); class='T_song12_wtt' title='"+this.container[i].title+"' align='center'>"+this.container[i].text+"</td></tr>";
   }
   reHtml+="</table></div>";
   document.writeln(reHtml);   
   document.all.showrightmenu.style.display = "none";
}
MenuContainer.prototype.hidden = function(){
   document.all.showrightmenu.style.display = "none";
   document.oncontextmenu="";
   for(var i=0;i<this.container.length;i++){
       var item = "menuitem_"+this.container[i].id; 
       item =  document.all(item);
       if(this.container[i].display)
          item.style.display = "";
       else
          item.style.display = "none";
   }
   
}
function menu_click(flag){
   var id = this.id;
   var parameters = this.parameters;
   var click;
   for(var i=0;i< this.container.length;i++){
      if(this.container[i].id==flag){
         click = this.container[i].onclick;
         break;
      }
   }
   if(click&&click!="")   
      eval(click);
   this.hidden();
}
function menu_mouseover(obj){   
   obj.className="T_song_mouseover";
}
function menu_mouseout(obj){   
   obj.className="T_song_mouseout";
}

function Menu(id,text,click,title,display,status){
   this.id = id;
   this.text = text;
   this.onclick = click;
   if(typeof title=="undefined")
      this.title = "";  
   else this.title = title;
   if(typeof display=="undefined")
      this.display = true;
   else this.display = display;   
   if(typeof status =="undefined")
      this.status = "";
   else this.status = status;   
}

function showMenu(id,parameters){
   document.oncontextmenu=click;
   menuContainer.showMenu(id,parameters);
}
function showRootMenu(id,parameters){
   showMenu(id,parameters);
}
function showParentMenu(id,parameters){
   showMenu(id,parameters);
}
function click() {    
     return false;
}  
